<?php
class Sessions
{
	private $sessions = array();
	private $users = array();
	
	public function __construct()
	{
		$database=$GLOBALS['DATABASE']->Recopy();
		$sql = "SELECT SessionID, UserID, Expires FROM Sessions ORDER BY Expires DESC";
		$database->executeSQL($sql);
		while($row=$database->getRow())
		{
			$expires = new DateTime($row['Expires']);
			$session = new Session($row['SessionID'],$row['UserID'],$expires);
			array_push($this->sessions,$session);
		}
		
		$sql = "SELECT UserID, count(UserID) as Count FROM Sessions GROUP BY UserID ORDER BY Count DESC";
		$database->executeSQL($sql);
		while($row=$database->getRow())
		{
			$this->users[$row['UserID']] = $row['Count'];
		}
	}
	
	public function getSessions(){return $this->sessions;}
	public function getUsers(){return $this->users;}
	
}

class Session
{
	private $sessionID;
	private $userID;
	private $expires;
	
	public function getSessionID(){return $this->sessionID;}
	public function getUserID(){return $this->userID;}
	public function getExpires(){return $this->expires;}
	
	public function __construct($sessionID,$userID,$expires)
	{
		$this->sessionID = $sessionID;
		$this->userID = $userID;
		$this->expires = $expires;
	}
}
